package com.practice.system.controller;

import com.practice.system.dto.BomAddDto;
import com.practice.system.dto.BomUpdateDto;
import com.practice.system.mapper.ProductMapper;
import com.practice.system.pojo.Bom;
import com.practice.system.pojo.Product;
import com.practice.system.service.BomService;
import com.practice.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("bom")
public class BomController {
    @Autowired
    BomService bomService;

    @Autowired
    ProductMapper productMapper;

    /**
     * bom数据
     * @param params
     * @return
     */
    @RequestMapping("/list")
    public R list(@RequestBody Map<String,Object> params) {
       return bomService.list(params);
    }

    /**
     * 根据bomid查询bom数据
     * @param id
     * @return
     */
    @RequestMapping("/bomById")
    public R BomById(@RequestParam("id") Integer id) {
        return bomService.selectBomById(id);
    }

    /**
     * 获取产品模型
     *
     * @return
     */
    @RequestMapping("/getModel")
    public R getModel() {
        List<Product> model = productMapper.getModel();
        return R.ok().put("data", model);
    }

    /**
     * 新增bom
     *
     * @param bom
     * @return
     */
    @RequestMapping("/add")
    public R BomAdd(@RequestBody Bom bom) {
        return bomService.addBomAddDto(bom);
    }

    /**
     * 修改bom和关联的数据
     * @param
     * @return
     */
    @RequestMapping("/update")
    public R BomUpdate(@RequestBody BomUpdateDto bomUpdateDto) {
       return bomService.updateBom(bomUpdateDto);
    }

    /**
     * 根据id删除bom
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public R BomDelete(@RequestParam("id") Integer id){
        return bomService.delete(id);
    }

}
